//
//  DSZShowScroll.m
//  7.13苏宁框架
//
//  Created by lovena on 15/7/18.
//  Copyright (c) 2015年 lovena. All rights reserved.
//
//要优化
#import "DSZShowScroll.h"
#import "Common.h"

#import "ShowImage.h"
#import "DSZShowWebViewController.h"
@implementation DSZShowScroll
+(id)ShowScroll
{
    return [[[NSBundle mainBundle]loadNibNamed:@"DSZShowScroll" owner:nil options:nil] lastObject];
}
-(void)awakeFromNib
{
    //滑动设置
    self.scrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, _label.bottom+5, 320, self.height-_label.height-5          -10)];
    self.scrollView.showsHorizontalScrollIndicator=NO;
    self.scrollView.decelerationRate=0.1;
    self.scrollView.delegate=self;
    [self addSubview:_scrollView];
    
//数据
    _scrollArray=[NSArray array];
    _scrollArray=[ShowScrollModel modelArrayWithFilename:@"scorll.plist"];
    int index=0;
    for(int i=0;i<_scrollArray.count;i++)
    {
        ShowScrollModel *smodel=self.scrollArray[i];
        ShowImage *image=[ShowImage showImage];
        image.model=smodel;
        image.delegate=self;
        image.tag=i;
       image.frame=CGRectMake(index,0, 120, 150);
        [self.scrollView addSubview:image];
        image.userInteractionEnabled=YES;

        
        index+=125;
    }
    self.scrollView.contentSize=CGSizeMake(self.scrollArray.count*125, 0);
    //添加一个手势识别器
    UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(gotoVC:)];
    [self.scrollView addGestureRecognizer:tap];
    
}

-(void)gotoVC:(UITapGestureRecognizer *)tap
{
    //获取点击的地方
    CGPoint point=[tap locationInView:self.scrollView];
    
    NSInteger index=point.x/125;
    ShowScrollModel *smodel=self.scrollArray[index];
    
    //代理
    if([self.delegate respondsToSelector:@selector(giveModel:)])
    {
        [self.delegate giveModel:smodel];
    }
    
    
}


-(void)addBuys:(ShopModel *)model
{
    if ([self.delegate respondsToSelector:@selector(addBuys2:)]) {
        [self.delegate addBuys2:model];
    }
}

@end
